<admintpl file="header" />
</head>
<body>
<style>
input .danxuan{ width:14px; height:14px;float:left;}
span .text{ margin-right: 30px;}
.radio {margin-top: 5px; margin-left: 15px; float: left;}
</style>
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li><a href="{:U('Materials/index')}">物料管理</a></li>
            <li class="active"><a href="{:U('Materials/edit', array('id'=>$card['id']))}" target="_self">编辑物料</a></li>
        </ul>
        <form action="{:U('Materials/edit_materials')}" method="post" class="form-horizontal js-ajax-form" enctype="multipart/form-data">
            <div class="row-fluid">
                <div class="span9">
                    <table class="table table-bordered">
                        <input type="text"  name="id" value="{$card.id}" class="hide"/>
                        <tr>
                            <th>名称</th>
                            <td colspan=3>
                                <input type="text" style="width:95%;" name="card_name" id="title" required value="{$card.card_name}" placeholder="请输入名称"/>
                            </td>
                        </tr>
                        <tr>
                            <th width="80">类型</th>
                            <td>
				          	<span class="switch_list cc">
				        		<foreach name="cardTypeList" item="vo">
									<label class="radio">
										<input type="radio" name="card_type" value="{$vo.id}"<if condition="$card['card_type'] eq $vo['id']" >checked</if>  disabled>
										<span>{$vo.name}</span>
									</label>
				                </foreach>
							</span>
                           </td>
                            <td colspan="2">
                            	<div id="redinput" style=display:<if condition="$card['card_type'] eq 1" ><else />none</if>>
									<input type="text" name="min_money" style="width:40%;" placeholder="红包最小值" value="{$card.min_money}">~
	                            	<input type="text" name="max_money" style="width:40%;"placeholder="红包最大值" value="{$card.max_money}">（分）
                            	</div>
                            	<div id="urlinput" style=display:<if condition="$card['card_type'] eq 3 || $card['card_type'] eq 4" ><else />none</if>>
									<input type="text" name="card_url" placeholder="链接地址" value="{$card.card_url}" style="width:95%;">
	                            </div>
                            </td>

                        </tr>
                        <tr>
                            <th>状态</th>
                            <td>
                                <select name="card_status">
                                    <foreach name="cardStatusList" item="vo" key="k">
                                        <option <if condition="($card['card_status'] eq $vo['id'])" >selected </if>  value="{$vo.id}">{$vo.name}</option>
                                    </foreach>
                                </select>
                            </td>
                            <th width="80">中奖词</th>
                            <td>
                            	<input type="text" name="congratulations" maxlength="20" value="{$card.congratulations}" />
                            </td>
                        </tr>
                        <tr>
                            <th>区域</th>
                            <td>
                                <select name="bind_location">
                                    <option value="0">全国</option>
<!--                                    <foreach name="cardStatusList" item="vo" key="k">
                                        <option value="{$vo.id}">{$vo.name}</option>
                                    </foreach>-->
                                </select>
                            </td>
                            <th>卡券总数量<br>红包总金额（分）</th>
                            <td><input type="text" readonly="" name="card_count" id="num" value="{$card['card_count']}" placeholder="请输入物料数量"> *如果是类型是【红包】则为现金</td>
                        </tr>
                        <tr>
                            <th>开始日期</th>
                            <td>
                                <input type="text" name="start_at"class="js-datetime" value="{$card.start_at}" autocomplete="off">
                            </td>
                            <th>结束日期</th>
                            <td>
                            	<input type="text" name="end_at"class="js-datetime" value="{$card.end_at}" autocomplete="off">
							</td>
                        </tr>
                        <tr>
                            <th>介绍</th>
                            <td colspan=3>
                                <textarea name="card_intro" id="description" required style="width: 98%; height: 50px;" placeholder="请填写物料介绍">{$card.card_intro}</textarea>
                            </td>
                        </tr>
                    </table>
                </div>
    		<div class="span3">
				<table width="100%"  cellpadding="2" cellspacing="2" class="table table-bordered">
						<tr><td><b>活动图片</b></td></tr>
						<if condition="$card['card_icon']">
							<tr><td>
								<img src="{$urlimg}{$card.card_icon}" name="card_icon">
								<input type="hidden" name="card_icon" value="{$card.card_icon}" />
							</td></tr>
			        	</if>
						<tr><td><input type="file" name="newcard_icon" id="imgfile" multiple="multiple" accept="image/*" style="width: 100%;"/></td></tr>
						<tr><td><img src="" id="img"></td></tr>
				</table>
			</div>
            </div>
            <div class="form-actions">
                <button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
                <a class="btn" href="{:U('Materials/index')}">返回</a>
            </div>
        </form>
    </div>
    <script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript">
	$("#imgfile").change(function(){
		var objUrl = getObjectURL(this.files[0]) ;
		console.log("objUrl = "+objUrl) ;
		if (objUrl) {
			$("#img").attr("src", objUrl) ;
		}
	}) ;
	function getObjectURL(file) {
		var url = null ;
		if (window.createObjectURL!=undefined) { // basic
			url = window.createObjectURL(file) ;
		} else if (window.URL!=undefined) { // mozilla(firefox)
			url = window.URL.createObjectURL(file) ;
		} else if (window.webkitURL!=undefined) { // webkit or chrome
			url = window.webkitURL.createObjectURL(file) ;
		}
		return url ;
	}
	</script>
</body>
</html>
